#include "WaypointComponent.h"

const HashedString WaypointComponent::type("WaypointComponent");	

WaypointComponent::WaypointComponent( Entity* parent ) : IComponent(parent)
{
	m_waypoint = new Pathing::Waypoint();
}
WaypointComponent::~WaypointComponent()
{
}

const HashedString& WaypointComponent::Type()
{
	return type;
}
std::string WaypointComponent::ToString() const
{
	char buffer[25];
	std::string result("");

	result += "WaypointLocation=";
	sprintf_s(buffer, "%.3f %.3f %.3f", m_waypoint->Location().X(), m_waypoint->Location().Y(), m_waypoint->Location().Z());

	result += " Radius=";
	sprintf_s(buffer, "%.3F", m_waypoint->Radius());
	result += buffer;
	return result;
}
bool WaypointComponent::ToXML( tinyxml2::XMLPrinter& printer )
{
	char buffer[25];
	sprintf_s(buffer, "%.3f %.3f %.3f", m_waypoint->Location().X(), m_waypoint->Location().Y(), m_waypoint->Location().Z());

	printer.OpenElement("Location");
	printer.PushAttribute("Vector", buffer);
	printer.CloseElement();

	printer.OpenElement("Radius");
	printer.PushAttribute("Value", m_waypoint->Radius());
	printer.CloseElement();
	return true;
}

float WaypointComponent::Radius()
{
	return m_waypoint->Radius();
}
void WaypointComponent::Radius( float radius )
{
	m_waypoint->Radius(radius);
}
void WaypointComponent::BindTo( Subject<Maths::Vector3D>& location )
{
	m_location = new DoubleValueTrigger<Maths::Vector3D>(&location, &m_waypoint->getLocation());
}

Pointer<Pathing::Waypoint>& WaypointComponent::Waypoint()
{
	return m_waypoint;
}